package com.wxmit.system.base.core;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;

import java.util.Collection;

/**
 * @Description ShushanPage
 * @Author huangxiong
 * @Date 2022/7/19 15:22
 * @Version V1.0
 */
@Data
public class ShushanPage<T> extends Page<T> {

    public ShushanPage() {
        super();
    }
    public ShushanPage(long current, long size, long total, boolean searchCount) {
        super(current,size,total,searchCount);
    }

    public static ShushanPage allPage() {
        return ShushanPage.of(1L,-1L,false);
    }

    public static <T> ShushanPage<T> of(long current, long size, boolean searchCount) {
        return of(current, size, 0L, searchCount);
    }
    public static <T> ShushanPage<T> of(long current, long size, long total, boolean searchCount) {
        return new ShushanPage(current, size, total, searchCount);
    }

    /**
     *  如果 order为空的话，就设置order参数，并把 column 改驼峰为下划线
     * @param column
     * @param asc
     */
    public void setUnderlineCaseOrderIfNull(String column,boolean asc){
        if(CollUtil.isEmpty(this.orders)){
            this.orders = ListUtil.of(new OrderItem(StrUtil.toUnderlineCase(column),asc));
        }
    }

    public boolean hasOrders() {
        return CollUtil.isNotEmpty(this.orders);
    }
}
